package com.hdu.suixianglu;

public class lc977 {
    class Solution {
        public int[] sortedSquares(int[] nums) {
            int len = nums.length;
            int[] ans = new int[len];
            int index = len - 1;
            for (int i = 0, j = len - 1; i <= j;) {
                if (nums[i] * nums[i] > nums[j] * nums[j]) {
                    ans[index--] = nums[i] * nums[i];
                    i++;
                } else {
                    ans[index--] = nums[j] * nums[j];
                    j--;
                }
            }
            return ans;
        }
    }
}
